<!--
 * @Author: 清羽
 * @Date: 2022-08-18 10:42:55
 * @LastEditTime: 2022-09-30 11:03:14
 * @LastEditors: you name
 * @Description:
-->
<!-- getList 页 -->
<template>
  <div
    class="login-container"
    style="padding:30px;"
  >
    <el-table
      :data="businessList"
      border
      style="width: 100%"
      :default-sort="{prop: 'created_at', order: 'descending'}"
    >
      <el-table-column
        label="创建时间"
        width="150"
        sortable
        prop="created_at"
      >
        <template slot-scope="scope">
          <span>{{scope.row.business.created_at|formatDate}}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="提交人"
        width="180"
      >
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.nickname }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="店铺名称"
        align="center"
      >
        <template slot-scope="scope">
          <span>{{scope.row.business.company_name}}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="状态"
        width="100"
        align="center"
        :filters="[{text:'待审核',value:2},{text:'未提交审核',value:1},{text:'已删除',value:0},{text:'未上架',value:3},{text:'已上架',value:4},{text:'已被下架',value:5}]"
        :filter-method="filterState"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.business.is_del==1">
            <el-tag type="danger">已删除</el-tag>
          </span>
          <span v-else-if="scope.row.business.is_check==null">
            <el-tag type="info">未提交审核</el-tag>
          </span>
          <span v-else-if="scope.row.business.is_check==0">
            <el-tag type="warning">待审核</el-tag>
          </span>
          <span v-else-if="scope.row.business.is_show==0">
            <el-tag type="warning">未上架</el-tag>
          </span>
          <span v-else-if="scope.row.business.is_show==1">
            <el-tag type="success">已上架</el-tag>
          </span>
          <span v-else-if="scope.row.business.down_shelf_info!==null">
            <el-tag type="danger">已被下架</el-tag>
          </span>
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        width="100"
        align="center"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            @click="select(scope.row.business._id)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>

</template>

<script>
export default {
  name: 'GetList',
  components: {},
  filters: {
    formatDate: function (value) {
      const date = new Date(value)
      const y = date.getFullYear()
      let MM = date.getMonth() + 1
      MM = MM < 10 ? '0' + MM : MM
      let d = date.getDate()
      d = d < 10 ? '0' + d : d
      let h = date.getHours()
      h = h < 10 ? '0' + h : h
      let m = date.getMinutes()
      m = m < 10 ? '0' + m : m
      let s = date.getSeconds()
      s = s < 10 ? '0' + s : s
      return y + '-' + MM + '-' + d + ' ' + h + ':' + m
    }
  },
  data () {
    return {
      businessList: []
    }
  },
  // 生命周期 - 创建完成（访问当前this实例）
  created () {

  },
  // 生命周期 - 挂载完成（访问DOM元素）
  mounted () {
    this.getData()
  },
  // 函数
  methods: {
    getData () {
      this.$api.business.getBusinessList().then(response => {
        this.businessList = response.data
        console.log("this.$api.business.getBusinessList => this.businessList", this.businessList)
      })
    },
    select (businessId) {
      this.$router.push({
        name: 'businessCheck',
        params: { businessId }
      })
    },
    filterState (value, row) {
      if (value == 0) { //已删除
        return row.business.is_del == 1
      } else if (value == 1) { //未提交审核
        return row.business.is_check == null
      } else if (value == 2) { //待审核
        return row.business.is_check == 0
      } else if (value == 3) { //未上架
        return row.business.is_show == 0
      } else if (value == 4) {//已上架
        return row.business.is_show == 1
      } else if (value == 5) {//已被下架
        return row.business.down_shelf_info !== null
      }
    }
  }
}
</script>
<style lang="scss" scoped>
/* @import url(); 引入css类 */
.getList {
}
</style>
